package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.business.Topic;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyContract;
import com.lkd.exception.LogicException;
import com.lkd.service.ChannelService;
import com.lkd.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Topic(TopicConfig.VMS_SUPPLY_TOPIC)
public class SupplyMsgHandler implements MsgHandler {


    @Autowired
    private ChannelService channelService;


    @Override
    public void process(String jsonMsg) {
        log.info("收到补货消息jsonMg={}",jsonMsg);
        if(StringUtils.isBlank(jsonMsg)){
            return ;
        }
        try {
            SupplyContract supplyContract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);
            channelService.supply(supplyContract);
        }catch (Exception e){
            e.printStackTrace();
            throw new LogicException("处理补货消息异常");
        }
    }
}
